/*
 * Vlabs Biological Web Elemments
 *
 * Copyright (c) 2009 Victor de la Torre (vdelatorre@cnio.es)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 * 
 * http://code.google.com/p/bwe/ 
 *
 */

(function($) { 
	$.bwe = $.bwe || {}; //Add the 'bwe' scope
	
	$.bwe.buidElement = function(container,label,elementOnClick,elementLabel,open){
	
		var id = Math.floor(Math.random()*1000);
		
		element = jQuery('<div style="display:inline;"><table style="display:inline" cellspacing="0"><tr><td class="bwe-label" style="color:#E80307"><b>'+label+'</b> <span class="parentesis">{</span><a href="#" id="trigger_'+id+'" onclick="'+elementOnClick+'('+id+',\''+label+'\')">'+elementLabel+'</a><span class="parentesis">}</span></td></tr><tr><td><div id="'+id+'" class="bwe-content bwe-hidden" valign="top" align="center" style="overflow:auto;"><img id="loading'+id+'" src="http://ubio.bioinfo.cnio.es/biotools/bwe/css/img/loading.gif"></div></td></tr></table></div>');
		container.append(element);
		
		if (open){
			$('#trigger_'+id).trigger('click');
		}
	}
	
	 $.bwe.animate = function(id,w,h){

 	   if ( $('#'+id).is('.bwe-hidden') ){
 	   	
 	   	$('#'+id).removeClass('bwe-hidden');	
 	   	$('#'+id).animate({ width: w, height: h}, 1000);
 	    return true;
 	   
 	   }else{
 	   	$('#'+id).empty();
 	   	$('#'+id).animate({ width: 0, height: 0}, 1000);
 	   	$('#'+id).addClass('bwe-hidden');
  	   	return false;
 	   }
 	}

	$.bwe.iFramed = function(fid,container,src,width,height,label){
	
			iframe = jQuery('<div class="bwe-container" style="width:'+width+'px;"><div class="bwe-title">'+label+'</div><div class="bwe-body" style="display:block;width:'+width+'px;height:'+height+'px;"><iframe id="'+fid+' "class="wframe" src="'+src+'" width="'+width+'" height="5000" frameborder="0" scrolling="no"></iframe></div></div><div class="bwe-label" style="width:'+width+'px;">Powered by '+label+'</div>');
		
		container.append(iframe);
		$(".bwe-body").jScrollPane({scrollbarWidth:5, scrollbarMargin:10, showArrows:false});
	};
	
})(jQuery);	